import { acceptHMRUpdate, defineStore } from "pinia"

export const useEtlStore = defineStore({
  id: "flow-etl",
  state: () => ({
    flowData: {
      nodeList: [],
      lineList: [],
    },
    data_etl_id: null,
    dragItem: {},
    currentItem: {},
    data_etl: {

    }
  }),
  getters: {
    nodeList (state) {
      return state.flowData.nodeList || [];
    },
    lineList (state) {
      return state.flowData.lineList || [];
    }
  },
  actions: {
    setFlowData (data) {
      this.flowData = data;
    },
    setDragItem (item) {
      this.dragItem = item;
    },
    setDataEtlId (id) {
      this.data_etl_id = id;
    },
    setCurrentItem (item) {
      this.currentItem = item;
    },
    setNodeList (nodes) {
      this.flowData.nodeList = nodes;
    },
    addNode (node) {
      this.flowData.nodeList.push(node);
    },
    reduceNode (index) {
      this.flowData.nodeList.splice(index, 1);
    },
    setLineList (lines) {
      this.flowData.lineList = lines;
    },
    addLine (line) {
      this.flowData.lineList.push(line);
    },
    reduceLine (index) {
      this.flowData.lineList.splice(index, 1);
    },
    setDataEtl (data) {
      this.data_etl = data
    }
  },
  // 开启数据缓存
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'flow-etl',
        storage: localStorage,
      }
    ]
  }
})
// if (import.meta.hot) {
//   import.meta.hot.accept(acceptHMRUpdate(useEtlStore, import.meta.hot))
// }
